package com.ilink.teacherservice.service.impl.bailian;

import com.aliyun.bailian20231229.models.GetIndexJobStatusResponse;
import com.aliyun.tea.TeaException;
import org.springframework.stereotype.Service;

@Service
public class GetIndexJobStatusService {

    /**
     * 返回格式
     * {
     *   "Status": 200,
     *   "Message": "success",
     *   "RequestId": "2FB7EEBC-AC0F-5D7F-AFF5-9655DAEEC7FB",
     *   "Data": {
     *     "Status": "COMPLETED",
     *     "Documents": [
     *       {
     *         "Status": "FINISH",
     *         "DocId": "file_e9a99f95147b4289888c766046369f1f_10249160",
     *         "Message": "导入成功",
     *         "DocName": "用大模型找prompt2309.03409",
     *         "Code": "FINISH"
     *       },
     *       {
     *         "Status": "FINISH",
     *         "DocId": "file_493bb69ac0584dd2a2504ed9398788d0_10249160",
     *         "Message": "导入成功",
     *         "DocName": "Codex2107.03374",
     *         "Code": "FINISH"
     *       }
     *     ],
     *     "JobId": "876bba3067fa40b592d85ca94ccc6bb2"
     *   },
     *   "Code": "Success",
     *   "Success": true
     * }
     **/
    public GetIndexJobStatusResponse getIndexJobStatus(com.aliyun.bailian20231229.Client client, String workspaceId, String jobId, String indexId) throws Exception {
        com.aliyun.bailian20231229.models.GetIndexJobStatusRequest getIndexJobStatusRequest = new com.aliyun.bailian20231229.models.GetIndexJobStatusRequest()
                .setJobId(jobId)
                .setIndexId(indexId);
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        java.util.Map<String, String> headers = new java.util.HashMap<>();
        try {
            // 复制代码运行请自行打印 API 的返回值
            return client.getIndexJobStatusWithOptions(workspaceId, getIndexJobStatusRequest, headers, runtime);
        } catch (TeaException error) {
            // 此处仅做打印展示，请谨慎对待异常处理，在工程项目中切勿直接忽略异常。
            // 错误 message
            System.out.println(error.getMessage());
            // 诊断地址
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
            throw new TeaException(error.getMessage(), error);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // 此处仅做打印展示，请谨慎对待异常处理，在工程项目中切勿直接忽略异常。
            // 错误 message
            System.out.println(error.getMessage());
            // 诊断地址
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
            throw new Exception(error.getMessage());
        }
    }
}
